{template 'admin_header'}
{if $operation == 'display'}

<form method="post" action="" id="listform">
	<div class="admin">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <li> <a class="button border-main icon-plus-square-o" href="{php echo $this->createMobileUrl('admin_manage', array('op' => 'manage_add'))}"> 添加内容</a> </li>
        <li>搜索：</li>
        
       
        <li>
          <input type="text" placeholder="请输入搜索关键字" name="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a></li>
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">ID</th>
        <th width="10%">部门</th>
        <th>类别</th>
        <th>问题</th>
        <th>时间</th>
        <th width="310">操作</th>
      </tr>
      {loop $list $v}
        <tr>
          <td>{$v['id']}</td>
          <td>{$v['department']}</td>
          <td>{$v['category']}</td>
          <td>{$v['question']}</td>
          <td>{$v['date']}</td>
          <td><div class="button-group"> <a class="button border-main" style="cursor: pointer;" href="{php echo $this->createMobileUrl('admin_manage', array('op' => 'manage_change','wt_id' => $v['id']))}"><span class="icon-edit"></span> 修改</a> <a class="button border-red" style="cursor: pointer;" onclick="manage_del({$v['id']})"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr>
   		{/loop}
        
     
      <tr>
        <td colspan="11"><div class="pagelist"> <a href="">上一页</a> <span class="current">1</span><a href="">2</a><a href="">3</a><a href="">下一页</a><a href="">尾页</a> </div></td>
      </tr>
    </table>
  </div>
</div>
</form>

{elseif $operation == 'manage_change'}
<div class="admin">
  <div class="panel admin-panel margin-top" id="add">
          <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 修改内容</strong></div>
          <div class="body-content">
            <form method="post" class="form-x" action="" id="myform">  
                <input type="hidden" value="{$wt_id}" name="wt_id">  
              <!-- 下拉框 -->
                  <div class="form-group">
                    <div class="label">
                      <label>部门：</label>
                    </div>
                    <div class="field">
                      <select name="" class="input w50" value="" onchange="manage_change_c(this.options[this.options.selectedIndex].value)">
                        {loop $bm $v}
                        <option value="{$v['id']}">{$v['department']}</option>
                        {/loop}
                      </select>
                      <div class="tips" title=""></div>
                    </div>
                  </div>
  
                  <div class="form-group">
                    <div class="label">
                      <label>类别：</label>
                    </div>
                    <div class="field">
                      <select name="category" class="input w50" id="select_de" >
                       
                      </select>
                      <div class="tips" title=""></div>
                    </div>
                  </div>
             
                  <div class="form-group">
                    <div class="label">
                      <label>问题描述：</label>
                    </div>
                    <div class="field">
                      <textarea type="text" class="input" name="question" style="height:120px;" value="">{$wt['question']}</textarea>
                      <div class="tips" title=""></div>
                    </div>
                  </div>
             
              <div class="form-group">
                <div class="label">
                  <label></label>
                </div>
                <div class="field">
  
                  <button class="button bg-main icon-check-square-o" type="button" onclick="manage_change()"> 提交</button>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>

      {elseif $operation == 'manage_add'}
      <div class="admin">
        <div class="panel admin-panel margin-top" id="add">
                <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 增加内容</strong></div>
                <div class="body-content">
                  <form method="post" class="form-x" action="" id="myform">    
                    <!-- 下拉框 -->
                        
                        <div class="form-group">
                          <div class="label">
                            <label>部门：</label>
                          </div>
                          <div class="field">
                            <select name="department" class="input w50" onchange="manage_add_c(this.options[this.options.selectedIndex].value)">
                              {loop $bm $v}
                              <option value="{$v['id']}">{$v['department']}</option>
                              {/loop}
                            </select>
                            <div class="tips" title=""></div>
                          </div>
                        </div>
        
                        <div class="form-group">
                          <div class="label">
                            <label>类别：</label>
                          </div>
                          <div class="field">
                            <select name="category" class="input w50" id="mySelect">
                                     
                            </select>
                            <div class="tips" title=""></div>
                          </div>
                        </div>
                   
                        <div class="form-group">
                          <div class="label">
                            <label>问题描述：</label>
                          </div>
                          <div class="field">
                            <textarea type="text" class="input" name="question" style="height:120px;" value="">{$wt['question']}</textarea>
                            <div class="tips" title=""></div>
                          </div>
                        </div>
                   
                        
        
                    <!-- 上传图片 -->
                    <!-- <div class="form-group">
                      <div class="label">
                        <label>图片：</label>
                      </div>
                      <div class="field">
                        <input type="text" id="url1" name="img" class="input tips" style="width:25%; float:left;" value="" data-toggle="hover" data-place="right" data-image="" title="">
                        <input type="button" class="button bg-blue margin-left" id="image1" value="+ 浏览上传" style="float:left;">
                        <div class="tipss">图片尺寸：1920*500</div>
                      </div>
                    </div> -->
        
        
                   
                    <div class="form-group">
                      <div class="label">
                        <label></label>
                      </div>
                      <div class="field">
        
                        <button class="button bg-main icon-check-square-o" type="button" onclick="manage_add()"> 提交</button>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
            </div>
  
      {/if}
</body>
<script type="text/javascript">
//修改操作
function manage_change(){
var formData = new FormData($("#myform")[0]);//获取表单数据  
     $.ajax({
     url: "{php echo $this->createMobileUrl('admin_manage_change')}",//提交地址 
     type: 'POST',
     data: formData,
     async: false,
     cache: false,
     contentType: false,
     processData: false,
     success: function (returndata) {
         if(returndata.status=='1'){
             
               alert(JSON.parse(returndata).message);
             }
         else{ 
           
             alert(JSON.parse(returndata).message);
             }
     },
      error: function (returndata) {
             alert('系统错误');
             }
         });

}

function manage_change_c(de_id){
  
  $.post("{php echo $this->createMobileUrl('admin_manage_ch')}",{de_id:de_id},function(returndata){
               if(JSON.parse(returndata).status== '1')
               {
                 var fl = [];
                 var fl = JSON.parse(returndata).data;
                var a = fl.length;
                console.log(fl);
                var obj=document.getElementById('select_de');

                for(var i=0;i<a;i++){ 
                  var q = fl[i];
                  var w = JSON.stringify(q);
              
                  var c_r = w.replace("{","");    
                  var c_t = c_r.replace("}","");
                  var c_y = c_t.replace(":","");
                  var c_u = c_y.replace(/\"/g,"");
                  var c_p = c_u.replace("category","");      //获得分类
                  var c_m = c_p.replace("id","");
                  var c_h = c_m.replace(":","");
                  var c_v = c_h.replace(",","");
                  var fl_c = c_v.replace(/[0-9]/ig,"");
                  
                 var g_id = w.replace(/[^0-9]/ig,"");        //获得分类的id
                 console.log(fl_c,g_id);
                 
                  obj.options[i]=new Option(fl_c,g_id); 
                }

               }
              else{
                  alert("系统错误");
              } 
              
               
           });
 
}

//删除操作
function manage_del(id){
 
    $.post("{php echo $this->createMobileUrl('admin_manage_del')}",{id:id},function(returndata){
               if(returndata.status== '1')
               {
                 alert(JSON.parse(returndata).message);
                 window.location.href="{php echo $this->createMobileUrl('admin_manage',array('op' => 'display'))}";
                  
               }
               else {
                 alert(JSON.parse(returndata).message);
                 window.location.href="{php echo $this->createMobileUrl('admin_manage',array('op' => 'display'))}";
               }
               
           });
}


//添加操作
function manage_add(){
  var formData = new FormData($("#myform")[0]);//获取表单数据  
     $.ajax({
     url: "{php echo $this->createMobileUrl('admin_manage_ad')}",//提交地址 
     type: 'POST',
     data: formData,
     async: false,
     cache: false,
     contentType: false,
     processData: false,
     success: function (returndata) {
         if(returndata.status=='1'){
               alert(JSON.parse(returndata).message);
               window.location.href="{php echo $this->createMobileUrl('admin_manage',array('op' => 'display'))}";
             }
         else{ 
             
             alert(JSON.parse(returndata).message);
             }
     },
      error: function (returndata) {
             alert('系统错误');
             }
         });


}

//下拉框联动
function manage_add_c(d_id){
  
  $.post("{php echo $this->createMobileUrl('admin_manage_add')}",{d_id:d_id},function(returndata){
               if(JSON.parse(returndata).status== '1')
               {
                 var fl = [];
                 var fl = JSON.parse(returndata).data;
                var a = fl.length;
                console.log(fl);
                var obj=document.getElementById('mySelect');

                for(var i=0;i<a;i++){ 
                  var q = fl[i];
                  var w = JSON.stringify(q);
              
                  var c_r = w.replace("{","");    
                  var c_t = c_r.replace("}","");
                  var c_y = c_t.replace(":","");
                  var c_u = c_y.replace(/\"/g,"");
                  var c_p = c_u.replace("category","");      //获得分类
                  var c_m = c_p.replace("id","");
                  var c_h = c_m.replace(":","");
                  var c_v = c_h.replace(",","");
                  var fl_c = c_v.replace(/[0-9]/ig,"");
                  
                 var g_id = w.replace(/[^0-9]/ig,"");        //获得分类的id
                 console.log(fl_c,g_id);
                 
                  obj.options[i]=new Option(fl_c,g_id); 
                }

               }
              else{
                  alert("系统错误");
              } 
              
               
           });
 
}

      

</script>
</html>